﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Quartz.Impl;

namespace Quartz.NET.Newer.WindowsFormsApp
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void buttonHelloJob_Click(object sender, EventArgs e)
        {
            var job = JobBuilder.Create<HelloJob>()
                .WithIdentity("job1", "group1")
                .Build();

            var trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .StartNow()
                //.WithCronSchedule("0/3 * * * * ? *", builder => builder.WithMisfireHandlingInstructionDoNothing())
                //.WithSimpleSchedule(builder =>
                //{
                //    builder.WithIntervalInSeconds(3)
                //        .RepeatForever();
                //})
                .WithSchedule(CronScheduleBuilder.CronSchedule("0/3 * * * * ? *").WithMisfireHandlingInstructionDoNothing())
                .Build();

            var scheduler = StdSchedulerFactory.GetDefaultScheduler().Result;
            scheduler.ScheduleJob(job, trigger).Wait();
        }
    }
}
